﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Security.Cryptography;
using System.Reflection;
using System.Text.RegularExpressions;
using System.ComponentModel;

namespace HashMe
{
    public static class HashTypes
    {

        public static String GetHash(String HashType,String pTextToHash)
        {
            
            Object[] parameter = {pTextToHash};
            MethodInfo mi = typeof(HashTypes).GetMethod("Get" + HashType + "Hash");
            String result = mi.Invoke(null, parameter).ToString();
            result = Regex.Replace(result, @"-", "");
            return result;
        }

        public static String GetMD5Hash(string pTextToHash)
        {
            if (String.IsNullOrEmpty(pTextToHash))
            {
                return string.Empty;
            }
            MD5 md5 = new MD5CryptoServiceProvider();
            byte[] textToHash = Encoding.Default.GetBytes(pTextToHash);
            byte[] result = md5.ComputeHash(textToHash);
            return System.BitConverter.ToString(result);
        }

        public static String GetSHA1Hash(String pTextToHash)
        {
            if (String.IsNullOrEmpty(pTextToHash))
            {
                return string.Empty;
            }
            SHA1 sha1 = new SHA1CryptoServiceProvider();
            byte[] textToHash = Encoding.Default.GetBytes(pTextToHash);
            byte[] result = sha1.ComputeHash(textToHash);
            return System.BitConverter.ToString(result);
        }

        public static String GetSHA256Hash(String pTextToHash)
        {
            if (String.IsNullOrEmpty(pTextToHash))
            {
                return string.Empty;
            }
            SHA256 sha256 = new SHA256CryptoServiceProvider();
            byte[] textToHash = Encoding.Default.GetBytes(pTextToHash);
            byte[] result = sha256.ComputeHash(textToHash);
            return System.BitConverter.ToString(result);
        }

        public static String GetSHA384Hash(String pTextToHash)
        {
            if (String.IsNullOrEmpty(pTextToHash))
            {
                return string.Empty;
            }
            SHA384 sha384 = new SHA384CryptoServiceProvider();
            byte[] textToHash = Encoding.Default.GetBytes(pTextToHash);
            byte[] result = sha384.ComputeHash(textToHash);
            return System.BitConverter.ToString(result);
        }

        public static String GetRIPEMD160Hash(String pTextToHash)
        {
            if (String.IsNullOrEmpty(pTextToHash))
            {
                return string.Empty;
            }
            RIPEMD160 rip = new RIPEMD160Managed();
            byte[] textToHash = Encoding.Default.GetBytes(pTextToHash);
            byte[] result = rip.ComputeHash(textToHash);
            return System.BitConverter.ToString(result);
        }

        public static String GetSHA512Hash(String pTextToHash)
        {
            if (String.IsNullOrEmpty(pTextToHash))
            {
                return string.Empty;
            }
            SHA512 sha512 = new SHA512CryptoServiceProvider();
            byte[] textToHash = Encoding.Default.GetBytes(pTextToHash);
            byte[] result = sha512.ComputeHash(textToHash);
            return System.BitConverter.ToString(result);
        }



    }
}